<template>
  <div class='app'>
    <h2>当前的和为:{{ $store.state.sum }}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="3">3</option>
      <option value="5">5</option>
    </select>
    <button @click="add">++</button>
    <button @click="reduce">--</button>
    <button @click="oddadd">当前和为奇数再加</button>
    <button @click="waitadd">等一等再加</button>
  </div>
</template>

<script>
export default {
  name: 'Num',
  data() {
    return {
      n: 1,
    };
  },
  methods: {
    add() {
      this.$store.dispatch('add', this.n);
    },
    reduce() {
      this.$store.dispatch('reduce', this.n);
    },
    oddadd() {
      this.$store.dispatch('oddadd', this.n);
    },
    waitadd() {
      this.$store.dispatch('waitadd', this.n);
    },
  },
};
</script>






<style scoped>
.app {
  background-color: cornsilk;
  padding: 15px;
  margin-top: 10px;
  box-shadow: 0 0 10px;
  text-align: right;
}
button {
  color: blue;
  font-size: 15px;
  margin: 0 6px;
}
</style>